import instacne from "../request";
import type { Ref } from "vue";

/**
 * 登录返回数据
 */
interface IAdminLoginParams {
    password: string;
    username: string;
}
interface IAdminLoginRes {
    tokenHead: string;
    token: string;
}
interface IAddReturnGoods {
    createTime: string;
    id: number;
    name: string;
    sort: number;
    status: number;
}
const adminLogin = (data: IAdminLoginParams): Promise<IAdminLoginRes> => {
    // instacne.post("/auth/login", data); 是一个 Promise 类型
    return instacne.post("/admin/login", data);
};

/**
 * 获取当前登录用户信息
 */
interface IAdminInfoRes {
    menus: IMenuItem[];
    icon: string;
    username: string;
    roles: string[];
}
const getAdminInfo = (): Promise<IAdminInfoRes> => {
    return instacne.get("/admin/info");
};

/**
 * /admin/list 根据用户名或者姓名获取用户列表
 */
interface IAdminListParams {
    keyword?: string | Ref<string>;
    pageNum?: number | Ref<number>;
    pageSize?: number | Ref<number>;
}

interface IAdminListItem {
    createTime: string;
    email: string;
    icon: string;
    id: number;
    loginTime: string;
    nickName: string;
    note: string;
    password: string;
    status: number;
    username: string;
}

interface IAdminListRes {
    list: IAdminListItem[];
    pageNum: number;
    pageSize: number;
    total: number;
    totalPage: number;
}

const getAdminList = (data?: IAdminListParams): Promise<IAdminListRes> => {
    return instacne.get("/admin/list", {
        params: data,
    });
};

/**
 * 新增用户
 * admin/register
 */
const adminRegister = (data: IAdminListItem): Promise<IAdminListItem> => {
    return instacne.post("/admin/register", data);
};

/**
 * /admin/update/{id}
 *  修改指定用户信息
 */
const adminUpdate = (data: IAdminListItem) => {
    return instacne.post(`/admin/update/${data.id}`, data)
}
/* 
     resource  /resource/list?pageNum=1&pageSize=10
*/
const getAdmineresource = (data?: IAdminListParams): Promise<IAdminListRes> => {
    return instacne.get("/resource/list", {
        params: data,
    });
};
/* 
    /menu/list/  菜单列表  
*/
const getAdminmenu = (data?: IAdminListParams): Promise<IAdminListRes> => {
    return instacne.get("/menu/list/0", {
        params: data,
    });
};

interface IGoodslistData {
    brandId?: number | Ref<number>
    keyword?: string | Ref<string>
    pageNum?: number | Ref<number>
    pageSize?: number | Ref<number>
    productCategoryId?: number | Ref<number>
    productSn?: string | Ref<string>
    publishStatus?: number | Ref<number>
    verifyStatus?: number | Ref<number>
}

interface IGoosOlldata {
    pageNum: number,
    pageSize: number,
    total: number,
    totalPage: number,
    list: any[]
}


/**
 * /product/list  查询商品
 */
const getGoodsList = (data: IGoodslistData): Promise<IGoosOlldata> => {
    return instacne.get('/product/list', { params: data })
}


// 角色列表信息
const getAdminRole = (data?: getAdminResources): Promise<IAdminListRes> => {
    return instacne.get('/role/list', {
        params: data
    })
}
// 角色列表
const getAdminallowMenu = (id: number): Promise<any[]> => {
    return instacne.get(`/role/listMenu/${id}`);
};
//所有菜单
const getmenus = (): Promise<IAdminListParams> => {
    return instacne.get("menu/treeList", {});
};
interface getAdminResources {
    keyword?: string | Ref<string>;
    pageNum?: number | Ref<number>;
    pageSize?: number | Ref<number>;
}
interface IRoleListItem {
    adminCount: number;
    createTime: string;
    description: string;
    id: number;
    name: string;
    sort: number;
    status: number;
}
//分配资源约束
interface resources {
    id: number;
    createTime: string;
    name: string;
    url: string;
    description: string;
    categoryId: number;
}
//分配资源
const getresourcesRole = (data: string): Promise<resources> => {
    return instacne.get(`role/listResource/${data}`);
};

//全部资源
const getresources = (): Promise<resources> => {
    return instacne.get("resource/listAll");
};
//  角色列表新增
const rolesRegister = (data: IRoleListItem): Promise<IRoleListItem> => {
    return instacne.post("/role/create", data);
};

// 商品品牌信息
const getProductbrand = (data?: IAdminListParams): Promise<IAdminListRes> => {
    return instacne.get('/brand/list', {
        params: data
    })
}
// 属性管理
const attribute = (data?: IAdminListParams): Promise<IAdminListRes> => {
    return instacne.get("/productAttribute/category/list", {
        params: data,
    })
}
// 订单查询
const getOrderQuery = (data?: IAdminListParams): Promise<IAdminListRes> => {
    return instacne.get('/order/{id}', {
        params: data
    })
}
// 添加品牌 /brand/create
interface createItem {
    bigPic: string,
    brandStory: string,
    factoryStatus: number,
    firstLetter: string,
    logo: string,
    name: string,
    showStatus: number,
    sort: number,
    id: number
  }
  const createItemAdd = (data: createItem): Promise<createItem> => {
    return instacne.post('/brand/create', data)
  }
  const createItemEdit = (data: number): Promise<createItem> => {
    return instacne.get(`/brand/${data}`)
  }
// 删除品牌
const getBrand = (data?: IAdminListParams): Promise<IAdminListRes> => {
    return instacne.get('/mall-admin/brand/delete/{id}', {
        params: data
    })
}
// 更新品牌
const updateBrand = (data?: IAdminListParams): Promise<IAdminListRes> => {
    return instacne.post('/mall-admin/brand/update/{id}', {
        params: data
    })
}
// productAttribute/create 商品属性添加
interface IAdminDelete {
    filterType: number,
    handAddStatus: number,
    inputList: string,
    inputType: number,
    name: string,
    productAttributeCategoryId: number,
    relatedStatus: number,
    searchType: number,
    selectType: number,
    sort: number,
    type: number
}
// 编辑商品 /brand/update/
const createItemEdits = (data: createItem): Promise<createItem> => {
    return instacne.post(`/brand/update/${data.id}`, {
      bigPic: data.bigPic,
      brandStory: data.brandStory,
      factoryStatus: data.factoryStatus,
      firstLetter: data.firstLetter,
      logo: data.logo,
      name: data.name,
      showStatus: data.showStatus,
      sort: data.sort,
  
    })
  }
// 属性列表
const adminForm = (
    data: AttributeListItiem | undefined
): Promise<IAdminListRes> => {
    console.log(data);
    return instacne.get(`/productAttribute/list/${data?.cid}`, {
        params: {
            pageNum: data?.pageNum,
            pageSize: data?.pageSize,
            type: data?.type,
        },
    });
};
// productAttribute/list/{cid} 商品属性列表
const AttributeList = (
    data: AttributeListItiem | undefined
  ): Promise<IAdminListRes> => {
    console.log(data);
  
    return instacne.get(`/productAttribute/list/${data?.cid}`, {
      params: {
        pageNum: data?.pageNum,
        pageSize: data?.pageSize,
        type: data?.type,
      },
    });
  };
  interface AttributeListItiem {
    cid?: number;
    pageNum?: number;
    pageSize?: number;
    type?: number;
  }
  interface IAdminListRes {
    list: IAdminListItem[];
    pageNum: number;
    pageSize: number;
    total: number;
    totalPage: number;
  }
// 删除属性列表
const adminDeleteForm = (data: number): Promise<IAdminDelete> => {
    return instacne.get(`/productAttribute/category/delete/${data}`)
}
interface AttributeListItiem {
    cid?: number;
    pageNum?: number;
    pageSize?: number;
    type?: number;
}
// 删除退货原因
const delRouterGoods = (data: number): Promise<null> => {
    return instacne.post(`/returnReason/delete?ids=${data}`);
  };

// 修改退货原因状态
interface IgoodsStatus {
    ids: number;
    status: number;
  }
  const changeReturnGoodsStatus = (data: IgoodsStatus): Promise<IgoodsStatus> => {
    return instacne.post(
      `/returnReason/update/status?status=${data.status}&ids=${data.ids}`
    );
  };

  // 添加退货请求
interface IAddReturnGoods {
    createTime: string;
    id: number;
    name: string;
    sort: number;
    status: number;
  }
  
  export const addReturnGoods = (
    data: IAddReturnGoods
  ): Promise<IAddReturnGoods> => {
    return instacne.post("/returnReason/create", data);
  };
  // 修改退货原因
const changeReturnGoods = (data: IAddReturnGoods): Promise<IAddReturnGoods> => {
    return instacne.post(`/returnReason/update/${data.id}`, data);
  };

  // 添加商品属性/productAttribute/create
interface AdminAddCategory {
    filterType: number,
    handAddStatus: number,
    inputList: string,
    inputType: number,
    name: string,
    productAttributeCategoryId: number,
    relatedStatus: number,
    searchType: number,
    selectType: number,
    sort: number
    type: number
  }
  const AdminAddItem = (data: AdminAddCategory): Promise<AdminAddCategory> => {
    console.log(data);
    return instacne.post(`/productAttribute/create`, {
      params: {
  
      }
    })
  }
  // 添加属性列表
interface AdminAdd {
    name: string,
    id: number,
  }
export {
    adminLogin,
    getAdminInfo,
    getAdminList,
    adminRegister,
    adminUpdate,
    getAdmineresource,
    getAdminmenu,
    getGoodsList,
    getAdminRole,
    getProductbrand,
    attribute,
    adminDeleteForm,
    getOrderQuery,
    rolesRegister,
    getAdminallowMenu,
    getBrand,
    updateBrand,
    getmenus,
    getresourcesRole,
    getresources,
    adminForm,
    AttributeList,
    delRouterGoods,
    changeReturnGoodsStatus,
    changeReturnGoods,
    AdminAddItem,
    createItemEdits,
    createItemEdit
};
export type { IAdminLoginParams, IAdminLoginRes, IAdminListItem, IGoosOlldata, IRoleListItem, IAddReturnGoods, AdminAddCategory,AdminAdd,IAdminListRes ,createItem,};

export function adminAddForm(row: IAdminListItem) {
    throw new Error('Function not implemented.');
}
